import { getTradeInfo, getOrderInfo, submitOrder, getPayInfo, geyPayStatus } from 'http'
const OK =200
export default {
    state: {
        tradeInfo: {},
        orderInfo: {},
        payInfo: {},
    },
    getters: {},
    mutations: {
        getTradeInfo(state,tradeInfo){
            state.tradeInfo = tradeInfo
        },
        getOrderInfo(state,orderInfo){
            state.orderInfo = orderInfo
        },
        getPayInfo(state,payInfo){
            state.payInfo = payInfo
        }
    },
    actions: {
        async getTradeInfo({ commit }) {
            const { code, data } = await getTradeInfo()
            if(code === OK){
                commit('getTradeInfo',data)
            }
        },
        async getOrderInfo({ commit },{page,limit}) {
            const { code, data } = await getOrderInfo(page,limit)
            if(code === OK){
                commit('getOrderInfo',data)
            }
        },
        async getPayInfo({ commit },orderId) {
            const { code, data } = await getPayInfo(orderId)
            if(code === OK){
                commit('getPayInfo',data)
            }
        },
        async submitOrder(store,{tradeNo, order}){
            const { code, data ,message} = await submitOrder(tradeNo, order)
            return {code,data,message}
        },
        async geyPayStatus(store,orderId){
            const {code} = await geyPayStatus(orderId)
            console.log(code)
            return code
            
        }

    }
}